package tacos.web.resources;

import org.springframework.hateoas.server.mvc.RepresentationModelAssemblerSupport;
import tacos.domain.Taco;
import tacos.web.resources.TacoResource;

public class TacoResourceAssembler extends RepresentationModelAssemblerSupport<Taco,TacoResource> {

    public TacoResourceAssembler(Class<?> controllerClass, Class<TacoResource> resourceType) {
        /**
         * 告诉超类创建的链接将会使用 controllerClass确定url路径
         */
        super(controllerClass, resourceType);
    }

    @Override
    protected TacoResource instantiateModel(Taco entity) {
        return new TacoResource(entity);
    }

    @Override
    public TacoResource toModel(Taco entity) {
        /**
         * 通过Taco创建TacoSource，并且设置一个self链接，这个链接的url是根据taco对象的id衍生出来的
         * 在内部toModel会调用instantiateModel实例化Resource对象
         */
        return createModelWithId(entity.getId(),entity,"tacos");
    }
}
